package com.jingdianjichi.oss.controller;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.jingdianjichi.oss.entity.Result;
import com.jingdianjichi.oss.service.FileService;
import com.jingdianjichi.oss.util.MinioUtil;
import com.sun.media.jfxmedia.logging.Logger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName:FileController
 * Package:com.jingdianjichi.oss.controller
 * Description:
 *
 * @Author fst
 * @Create 2024/10/3 20:43
 * @Version 1.0
 */
@RestController
@Slf4j
public class FileController
{
    @Resource
    private FileService fileService;


    @RequestMapping("/testGetAllBuckets")
    public String testGetAllBuckets() throws Exception {
        List<String> allBucket=fileService.getAllBucket();
        return allBucket.get(0);
    }

    @RequestMapping("/getUrl")
    public String getUrl(String bucketName,String objectName) throws Exception
    {
        return fileService.getUrl(bucketName,objectName);
    }

    @RequestMapping("/upload")
    public Result<String> upload (MultipartFile uploadFile, String bucket, String objectName)
    {
        String url = fileService.uploadFile(uploadFile, bucket, objectName);
        return Result.ok(url);
    }

}
